package com.treasure.hunt.api

import com.module.lemlin.mode.SubscribeListener
import com.treasure.hunt.api.subscribe.subscribe
import com.treasure.hunt.entity.*
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import rxhttp.RxHttp
import java.util.concurrent.TimeUnit


/**
 * 获取抽奖次数
 * type:1=普通寻宝,2=豪华寻宝,3=九色格,4=翻牌
 * */
fun luckyGetLuckDraw(
    type: Int, listener: SubscribeListener<LuckyNumResponse>
): Disposable = subscribe(
    RxHttp.get("/api/luck_draw/get_luck_draw")
        .add("type", type)
        .asClass(LuckyNumResponse::class.java)
    , listener
)

/**
 * 普通寻宝抽奖
 * */
fun luckyOrdinaryChest(
    listener: SubscribeListener<LuckyGiftResponse>
): Disposable = subscribe(
    Observable.timer(4, TimeUnit.SECONDS).flatMap {
        RxHttp.get("/api/luck_draw/ordinary_chest")
            .asClass(LuckyGiftResponse::class.java)
    }
    , listener
)

/**
 * 豪华寻宝抽奖
 * */
fun luckyLuxuryChest(
    listener: SubscribeListener<LuckyGiftResponse>
): Disposable = subscribe(
    Observable.timer(4, TimeUnit.SECONDS).flatMap {
        RxHttp.get("/api/luck_draw/luxury_chest")
            .asClass(LuckyGiftResponse::class.java)
    }
    , listener
)

/**
 * 幸运翻牌抽奖
 * */
fun luckyFlop(
    position: Int, listener: SubscribeListener<LuckyFlopResponse>
): Disposable = subscribe(
    RxHttp.postForm("/api/luck_draw/lucky_flop")
        .add("position", position)
        .asClass(LuckyFlopResponse::class.java)
    , listener
)

/**
 * 九色格列表
 * */
fun luckyTurntable(
    page: Int, listener: SubscribeListener<LuckyGridListResponse>
): Disposable = subscribe(
    RxHttp.get("/api/luck_draw/turntable")
        .add("page", page)
        .asClass(LuckyGridListResponse::class.java)
    , listener
)

/**
 * 九色格抽奖
 * */
fun luckyTurntableWinningThePrize(
    listener: SubscribeListener<LuckyGridResponse>
): Disposable = subscribe(
    Observable.timer(2, TimeUnit.SECONDS).flatMap {
        RxHttp.get("/api/luck_draw/turntable_winning_the_prize")
            .asClass(LuckyGridResponse::class.java)
    }
    , listener
)

/**
 * 九色格排行榜
 * */
fun luckyTurntableRanking(
    listener: SubscribeListener<LuckyRankingResponse>
): Disposable = subscribe(
    RxHttp.get("/api/luck_draw/turntable_ranking")
        .asClass(LuckyRankingResponse::class.java)
    , listener
)